package com.xk.meeting.back.controller;

import com.xk.meeting.entity.Admin;
import com.xk.meeting.service.AdminService;
import com.xk.meeting.service.AdminServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/back/updateAdmin")
public class UpdateAdminServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String password = request.getParameter("password");

        HttpSession session = request.getSession();
        Admin admin = (Admin)session.getAttribute("admin");

        AdminService adminService = new AdminServiceImpl();
        int count = adminService.update(admin.getId(),password);

        if (count > 0){
            request.setAttribute("msg","修改成功");
            request.getRequestDispatcher("upAdmin.jsp").forward(request,response);
        }else {
            response.sendRedirect("../errorPage.jsp");
        }

    }
}
